#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMessageBox>
#include <QStackedWidget>
#include <pthread.h>

//#include <user.h>

#include <iostream>
#include <string>
#include <pthread.h>
#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/connectionlistener.h>
#include <gloox/presencehandler.h>
#include <gloox/connectiontcpclient.h>
#include <gloox/messagesession.h>
#include <gloox/message.h>
#include <gloox/messageeventfilter.h>
#include <gloox/messageeventhandler.h>
#include <gloox/chatstatefilter.h>
#include <gloox/chatstatehandler.h>
#include <gloox/messagesessionhandler.h>
#include <gloox/subscriptionhandler.h>
#include <gloox/privatexmlhandler.h>
#include <gloox/rostermanager.h>
#include <qobject.h>


//#include "../headers/user.h"

using namespace std;
using namespace gloox;

class UserClient;
class MainWindow;

namespace Ui {
    class MainWindow;

}
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void CallSend();
    void CallReceive();

    UserClient              *user;
    void DisplayReceivedMessage(string s);

private:
    Ui::MainWindow          *ui;
    pthread_t               t;


private slots:
    void on_pushButton_3_clicked();
    void on_lineEdit_6_returnPressed();
    void on_pushButton_2_clicked();
    void on_pushButton_clicked();
};

void* DoConnect(void*);

class UserClientCredentials
{
private:
        string	iUserName;
        string 	iPassword;
        string 	iHost;
public:
        UserClientCredentials()
        {

        }
        UserClientCredentials(string aUserName, string aPassword, string aHost) : iUserName(aUserName), iPassword(aPassword), iHost(aHost){ }
    string getHost() const
    {
        return iHost;
    }
    string getPassword() const
    {
        return iPassword;
    }
    string getUserName() const
    {
        return iUserName;
    }
    void setHost(string aHost)
    {
        iHost = aHost;
    }
    void setPassword(string aPassword)
    {
        iPassword = aPassword;
    }
    void setUserName(string aUserName)
    {
        iUserName = aUserName;
    }
};


class UserClient : public MessageHandler, MessageSessionHandler, ConnectionListener, MessageEventHandler, ChatStateHandler
{
public:
        ConnectionError er;
        bool 	iConnected;
        MainWindow *parent;
public:
        //ctor and dtor
        UserClient();
        ~UserClient();

        //user details
        void SetUserDetails(UserClientCredentials aUserCredentials);
        void SetDestinationUser(UserClientCredentials aUserCredentials);
        //connection related
        bool ConnecttosServer();

        //virtual functions
        virtual void handlePresence( const Presence& presence );
        virtual void onConnect();
        virtual bool onTLSConnect(const CertInfo& info);
        virtual void onDisconnect(ConnectionError e );
        virtual void handleMessage( const Message& msg, MessageSession* session = 0 );
        virtual void handleMessageEvent( const JID& from, MessageEventType event );
        virtual void handleMessageSession( MessageSession* session );
        virtual void handleChatState( const JID& from, ChatStateType state );

        //return client JID
        JID	GetJid()
        {
                return iUserJid;
        }

public:
        Client					*j;
        string 					iUserJidString, iDestJidString;
        JID					iUserJid, iDestJid;
        UserClientCredentials                   iUser, iDestUser;

        //MessageEventFilter	*iMessageEventFilter;
        MessageSession			*iMessageSession;
        ChatStateFilter			*iChatStateFilter;
};

inline void DisplayMessage(string str)
{
        cout << endl <<str <<endl;
}




#endif // MAINWINDOW_H
